﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace SmartMap.Domain.Controllers
{
    public class AdminController
    {
        public static Admin Current
        {
            get
            {
                return HttpContext.Current.Session["SessionAdmin"] as Admin;
            }
        }

        public static bool IsAuthenticated
        {
            get
            {
                if (HttpContext.Current.Session["IsAuthenticated"] != null
                    && HttpContext.Current.Session["IsAuthenticated"].ToString() != "false")
                {
                    return true;
                }
                else return false;
            }

        }

        public static void Login(string username, string password)
        {
            var login = SmartMap.Data.DataAccess.AdminData.Login(username, password);
            if (login != null)
            {
                Admin SessionAdmin = new Admin();
                SessionAdmin.AdminID = login.AdminID;
                SessionAdmin.AdminTypeID = login.AdminTypeID;
                SessionAdmin.AdminUserName = login.AdminUserName;
                HttpContext.Current.Session["SessionAdmin"] = SessionAdmin;
            }
        }

        public static void LogOut()
        {
            HttpContext.Current.Session["IsAuthenticated"] = null;
        }
    }
}
